<template>
  <view>
    <u-tabs
      ref="tabs"
      :list="list"
      :is-scroll="false"
      :current="current"
      @change="change"
      bar-height="6"
      bar-width="50"
      active-color="#1D2129"
      inactive-color="#767676"
      :bar-style="{
        backgroundColor: '#F14141'
      }"
    ></u-tabs>
    <view v-if="current == 0" class="back-box">
      <view>
        <view class="back-price">
          <text>可提现金额：</text
          ><text class="back-num"
            >￥{{ userInfo.cashBackAmountUsable.toFixed(2) }}</text
          ><text
            >(冻结金额：￥{{ userInfo.cashBackAmountFrozen.toFixed(2) }})</text
          >
        </view></view
      >
      <view class="tips"
        >可提现金额：可用于在提现或在当前小程序商城中进行消费；</view
      >
      <view>
        <u-form :model="form" ref="uForm" border-bottom>
          <u-form-item required label="提现金额" prop="name" label-width="200">
            <u-input
              type="digit"
              input-align="right"
              :maxlength="12"
              placeholder="请输入提现金额"
              v-model="form.backPrice"
            />
          </u-form-item>
        </u-form>
        <view class="tips">
          每笔提现金额0.1-500元，每日最多可提现5笔。<br />
          提现后，提现金额将支付到当前用户的微信余额中，请注意查收！
        </view>
      </view>
      <button
        class="u-reset-button money-button"
        hover-class="co-primary-button--hover"
        @click="submit"
      >
        提交
      </button>
    </view>
    <view v-if="current == 1" class="back-box">
      <view>
        <view class="back-price">
          <text>不可提现金额：</text
          ><text class="back-num"
            >￥{{ userInfo.bonusAmountUsable.toFixed(2) }}</text
          ><text
            >(冻结金额：￥{{ userInfo.bonusAmountFrozen.toFixed(2) }})</text
          >
        </view></view
      >
      <view class="tips">不可提现金额：可用于在当前小程序商城中进行消费；</view>
    </view>
  </view>
</template>

<script>
import { Payouts } from '@/api/user'
// 不允许请求的type

export default {
  options: { styleIsolation: 'shared' },
  data() {
    return {
      form: {
        backPrice: ''
      },
      current: 0,
      list: [
        {
          name: '可提现金额'
        },
        {
          name: '不可提现金额'
        }
      ]
    }
  },
  computed: {
    userInfo() {
      return this.$store.state.userInfo
    }
  },
  components: {},
  onLoad() {
    this.getInit()
  },

  methods: {
    // 提现
    submit() {
      if (this.form.backPrice) {
        let params = { amount: Number(this.form.backPrice) }
        Payouts(params).then((res) => {
          if (res.data.code == 200) {
            this.$store.dispatch('updateUserinfo')
            uni.showToast({
              title:'已发起提现申请，请耐心等待金额到账!'
            })
            this.form.backPrice = ''
          } else {
            uni.showToast({
              icon: 'none',
              title: res.data.msg
            })
          }
          console.log(res, '-=-=-=-')
        })
      } else {
        uni.showToast({
          icon: 'none',
          title: '请输入提现金额！'
        })
      }
    },
    change(index) {
      this.current = index
    },
    getInit() {}
  }
}
</script>

<style lang="scss" scoped>
.back-box {
  margin: 24rpx;
  padding: 32rpx;
  background: #fff;
  .back-price {
    font-weight: 400;
    font-size: 30rpx;
    color: #1d2129;
  }
  .back-num {
    font-size: 32rpx;
    color: #f14141;
    line-height: 44rpx;
  }
  .tips {
    margin-top: 15rpx;
    font-size: 22rpx;
    color: #86909c;
    line-height: 40rpx;
  }
}
::v-deep u-form-item {
  font-size: 30rpx;
  color: #1d2129;
}
.money-button {
  margin-top: 300rpx;
  height: 80rpx;
  background: linear-gradient(323deg, #ff4564 0%, #f14141 14%, #fc843b 100%);
  border-radius: 200rpx 200rpx 200rpx 200rpx;
  font-size: 36rpx;
  color: #ffffff;
  line-height: 80rpx;
}
</style>
